package com.yaorange.nongjt.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.enums.BusinessType;
import com.yaorange.nongjt.domain.QualificationCertificate;
import com.yaorange.nongjt.service.IQualificationCertificateService;
import com.yaorange.common.utils.poi.ExcelUtil;
import com.yaorange.common.core.page.TableDataInfo;

/**
 * 合格证管理Controller
 * 
 * @author hzliu
 * @date 2025-09-23
 */
@RestController
@RequestMapping("/nongjt/certificate")
public class QualificationCertificateController extends BaseController
{
    @Autowired
    private IQualificationCertificateService qualificationCertificateService;

    /**
     * 查询合格证管理列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualificationCertificate qualificationCertificate)
    {
        startPage();
        List<QualificationCertificate> list = qualificationCertificateService.selectQualificationCertificateList(qualificationCertificate);
        return getDataTable(list);
    }

    /**
     * 导出合格证管理列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:export')")
    @Log(title = "合格证管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualificationCertificate qualificationCertificate)
    {
        List<QualificationCertificate> list = qualificationCertificateService.selectQualificationCertificateList(qualificationCertificate);
        ExcelUtil<QualificationCertificate> util = new ExcelUtil<QualificationCertificate>(QualificationCertificate.class);
        util.exportExcel(response, list, "合格证管理数据");
    }

    /**
     * 获取合格证管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(qualificationCertificateService.selectQualificationCertificateById(id));
    }

    /**
     * 新增合格证管理
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:add')")
    @Log(title = "合格证管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualificationCertificate qualificationCertificate)
    {
        return toAjax(qualificationCertificateService.insertQualificationCertificate(qualificationCertificate));
    }

    /**
     * 修改合格证管理
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:edit')")
    @Log(title = "合格证管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualificationCertificate qualificationCertificate)
    {
        return toAjax(qualificationCertificateService.updateQualificationCertificate(qualificationCertificate));
    }

    /**
     * 删除合格证管理
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:remove')")
    @Log(title = "合格证管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(qualificationCertificateService.deleteQualificationCertificateByIds(ids));
    }
}
